/*
 * @Author: mikey.zhaopeng
 * @Date:   2016-08-04 16:31:41
 * @Last Modified by:   mikey.zhaopeng
 * @Last Modified time: 2016-08-04 17:13:13
 */


'use strict';
define([
    '../../../framework/base/baseView',
    '../../../framework/bean/admarket',
    'text!../tpl/optlog.html'
], function (
    BaseView,
    admarketBean,
    tpl
) {
        function me() {
            BaseView.apply(this, arguments);
            var self = this;
            this.init = function (_param) {
                self.$root = $('#opt-logs');
                var params = {
                    id: _param.adMarketTargetId
                };
                admarketBean.getLog(params, function (result) {
                    self.render(result);
                });
            }

            this.render = function (data) {

                var html = _.template(I18N.parse(tpl, 'adOptimize'))({
                    d: data
                });

                self.$root.empty().html(html);
                self.event();
            }

            this.event = function () {
                self.$root.find('tbody tr[data-ownid]').off('click').on('click', $.proxy(self.toggleClass, self));
                self.$root.find('tbody th[data-adid]').off('click').on('click', $.proxy(self.highlightAd, self));
            }


            this.toggleClass = function (e) {
                var id = $(e.currentTarget).data('ownid');
                $('#' + id).toggleClass('hidden');


            }

            /**
             * 高亮广告
             */
            this.highlightAd = function (e) {
                var adid = $(e.currentTarget).data('adid');
                var $treable =  $('.ndp-treable-wrapper ul.treable-body');
                $treable.find('li.treable-item[data-id^="ad-"]').removeClass('anim_image_green');
                $treable.find('li.treable-item[data-id^="ad-'+adid+'"]').addClass('anim_image_green');
            }

        }
        return me;
    }
);
